package com.ruoyi.web.controller.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.controller.api.model.OrderModel;
import com.ruoyi.wl.domain.WlOrder;
import com.ruoyi.wl.domain.WlTrackData;
import com.ruoyi.wl.domain.WlTrackResp;
import com.ruoyi.wl.service.IWlOrderService;
import com.ruoyi.wl.service.IWlTrackDataService;
import com.ruoyi.wl.service.IWlTrackRespService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author laogou
 * @Date 2021/7/18 22:01
 * @Description
 */
@CrossOrigin
@Api("订单查询接口")
@RestController
@RequestMapping("/api/order")
public class OrderApiController extends BaseApiController {
    @Autowired
    public IWlOrderService iWlOrderService;
    @Autowired
    private IWlTrackRespService wlTrackRespService;

    @Autowired
    private IWlTrackDataService wlTrackDataService;

    /**
     * 查看列表
     */
    @GetMapping("/list")
    public AjaxResult list( WlOrder order)
    {
        startPage();
        List<WlOrder> list = iWlOrderService.selectWlOrderList(order);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 查看详细
     */
    @GetMapping("/detail")
    public AjaxResult detail( WlOrder order)
    {
        WlOrder wlOrder = iWlOrderService.selectWlOrderById(order.getId());
        OrderModel model=new OrderModel();

        if(wlOrder!=null &&  StringUtils.isNotEmpty(wlOrder.getNu())) {
            WlTrackResp wlTrackRespParam = new WlTrackResp();
            wlTrackRespParam.setCom(wlOrder.getCom());
            wlTrackRespParam.setNu(wlOrder.getNu());
            List<WlTrackResp> trackRespList = wlTrackRespService.selectWlTrackRespList(wlTrackRespParam);
            if (trackRespList.size() > 0) {
                WlTrackResp resp=trackRespList.get(0);
                model.setId(resp.getId());
                model.setNu(resp.getNu());
                model.setCom(resp.getCom());
                model.setMessage(resp.getMessage());
                model.setCondition(resp.getCondition());
                model.setIscheck(resp.getIscheck());
                model.setState(resp.getState());
                model.setStatus(resp.getStatus());
                model.setReturnCode(resp.getReturnCode());
                model.setResult(resp.getResult());
                WlTrackData wlTrackDataParam = new WlTrackData();
                wlTrackDataParam.setNu(wlOrder.getNu());
                List<WlTrackData> trackDataList = wlTrackDataService.selectWlTrackDataList(wlTrackDataParam);
                model.setWlTrackDataList(trackDataList);
                return  AjaxResult.success(model);
            }
        }

        return AjaxResult.warn("暂无数据",model);
    }
}
